﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'SelectMovimientosPropios')
	BEGIN
		DROP  Procedure  SelectMovimientosPropios
	END

GO

CREATE Procedure SelectMovimientosPropios

AS
BEGIN

	SET NOCOUNT ON

	SELECT
	M.[movimientoID],
	M.[loteID],
	M.[almacenID],
	M.[cantidad],
	M.[motivo],
	M.[saldo],
	M.[operacionID],
	M.[personalID],
	M.[fecha],
	L.insumoID,
	L.numero AS lote,
	I.nombre AS insumo,
	A.nombre AS almacen
	FROM [Movimientos] AS M
	INNER JOIN Lotes AS L ON M.loteID = L.loteID
	INNER JOIN Insumos AS I ON L.insumoID = I.insumoID
	INNER JOIN Almacenes AS A ON M.almacenID = A.almacenID
	WHERE M.[motivo] IN (5,6,7,8)

	SET NOCOUNT OFF

END

GO

GRANT EXEC ON SelectMovimientosPropios TO PUBLIC

GO


